package com.cy.pj.notices.web.advice;

import com.cy.pj.notices.web.pojo.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;



/**
 * @RestControllerAdvice 注解描述的类,为spring web模块定义的全局异常处理类
 * 当我们在@RestController/@Controller注解描述的类或父类中没有处理异常,
 * 则系统会找@RestControllerAdvice注解描述的全局异常处理类,可以通过此类中的
 * 异常处理方法对异常进行处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger log =
            LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(RuntimeException.class)
    public JsonResult doHandleRuntimeException(
            RuntimeException e) {
        e.printStackTrace();
        log.error("exception msg is {}", e.getMessage());
        return new JsonResult(e);
    }
}

